package some.member.profil.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import some.member.profil.domain.ProfilMemberCommand;


public class ProfilValidator implements Validator{

	@Override
	public boolean supports(Class<?> clazz) {
		return ProfilMemberCommand.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "content","required");
		
		ProfilMemberCommand profilCommand = (ProfilMemberCommand)target;
		
		if(profilCommand.getAge() == 0 || profilCommand.getAge() > 100){
			errors.rejectValue("age", "numberValidate");
		}
		if(profilCommand.getHeight() == 0 || profilCommand.getHeight() > 220){
			errors.rejectValue("height", "numberValidate");
		}
		if(profilCommand.getFile() == null || profilCommand.getFile().isEmpty()){
			errors.rejectValue("file","required");
		}
	}

}
